import java.io.*;
import java.awt.*;
import java.awt.event.*;

public class JAPI_Componentlistener implements ComponentListener
{
	JAPI_SocketOutputStream as;
	int id;
	int debuglevel=0;
	int type;

	public JAPI_Componentlistener(int object_id, JAPI_SocketOutputStream action , int t)
	{
		as = action;
		id = object_id;
		type = t;
	}

	public void componentResized(ComponentEvent e)
	{
		if(type==JAPI_Const.J_RESIZED)
		{
			Component c = (Component)e.getSource();
        	if(c instanceof JAPI_Canvas)
        	 	((JAPI_Canvas)c).noticeResize();
			sendid();
		}
	}

    public void componentHidden(ComponentEvent e)
    {
		if(type==JAPI_Const.J_HIDDEN)
			sendid();
	}

    public void componentMoved(ComponentEvent e)
    {
		if(type==JAPI_Const.J_MOVED)
			sendid();
	}

    public void componentShown(ComponentEvent e)
    {
		if(type==JAPI_Const.J_SHOWN)
			sendid();
	}

	public void sendid()
	{
		if(debuglevel > 1) System.out.println("ComponentListener for Object : "+this.id);
		try
		{
			as.sendInt(id);
		}
		catch(IOException exce) {}
	}

	public void setdebuglevel(int level)
	{
		debuglevel=level;
	}
}

